// src/router.tsx
import {BrowserRouter, Routes, Route} from 'react-router-dom';
import Login from "./pages/Login/Login.tsx";
import SuperAdminMainWindow from "./pages/SuperAdminMainWindow/SuperAdminMainWindow.tsx";
import Register from "./pages/Register/Register.tsx";
import ForgetPassword from "./pages/ForgetPassword/ForgetPassword.tsx";
import AdminMainWindow from "./pages/AdminMainWindow/AdminMainWindow.tsx";
import UserMainWindow from "./pages/UserMainWindow/UserMainWindow.tsx";
import {useIdentityCheck} from "./hooks/useIdentityCheck.ts";

const Router = () => {
    return (
        <BrowserRouter>
            <Routes>
                <Route path="/" element={<Login/>}/>
                <Route path="/register" element={<Register/>}/>
                <Route path="/forgetPassword" element={<ForgetPassword/>}/>
                {/* 受保护的路由 */}
                <Route path="/userMainWindow" element={
                    <UserMainWindowWrapper/>
                }/>
                <Route path="/superAdminMainWindow" element={
                    <SuperAdminMainWindowWrapper/>
                }/>
                <Route path="/adminMainWindow" element={
                    <AdminMainWindowWrapper/>
                }/>
            </Routes>
        </BrowserRouter>
    );
};

const UserMainWindowWrapper = () => {
    useIdentityCheck('employee', '/'); // 只有 identity 为 'employee' 的用户可以访问
    return <UserMainWindow/>;
};

const SuperAdminMainWindowWrapper = () => {
    useIdentityCheck('superAdmin', '/'); // 只有 identity 为 'superAdmin' 的用户可以访问
    return <SuperAdminMainWindow/>;
};

const AdminMainWindowWrapper = () => {
    useIdentityCheck('admin', '/'); // 只有 identity 为 'admin' 的用户可以访问
    return <AdminMainWindow/>;
};

export default Router;
